/**
 * Created by lixinkun on 2017/4/20.
 */
'use strict';
import * as types from '../actions/actionTypes';
//我们把state的对象设置成为只读
const initialState = {
    loading: false,
    hasData: false,
    error: false,
    dataSource: {},
    dataTime: ''
}


//这个就是reducer
export default function homeDataState(state=initialState, action){
    //把state进行更新嘛，返回一个新的state
    switch (action.type){
        //确保reducer的纯函数性，我们不能改变默认的state，只能返回全新的对象
        case types.FETCH_HOME_DATE_REQUEST:
            return Object.assign({}, state, {
                ...state,
                loading: true,
                error: false
            });
        case types.FETCH_HOME_DATA_SUCCESS:
            return Object.assign({}, state, {
                ...state,
                loading: false,
                hasData: true,
                dataSource: action.dataSource,
                dataTime: action.dataTime
            });
        case types.FETCH_HOME_DATA_FAILURE:
            return Object.assign({}, state, {
                ...state,
                loading: false,
                error: true
            });
        default:
            return state;
    }
}